package org.example.spring.carsalemanagementsystem.service.impl;

import lombok.RequiredArgsConstructor;
import org.example.spring.carsalemanagementsystem.dao.AccessoryDao;
import org.example.spring.carsalemanagementsystem.entity.Accessory;
import org.example.spring.carsalemanagementsystem.service.AccessoryService;
import org.example.spring.carsalemanagementsystem.utils.IDUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class AccessoryServiceImpl implements AccessoryService {
    private final AccessoryDao accessoryDao;

    @Override
    public List<Accessory> selectByCarId(String carid) {
        return accessoryDao.selectByCarId(carid);
    }

    @Override
    public void insertOne(Accessory accessory) {
        accessory.setAccessoryid(IDUtil.getId());
        accessory.setCreatetime(LocalDateTime.now());
        accessoryDao.insertOne(accessory);
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (ids.size() > 0) {
            accessoryDao.deleteBatch(ids);
        }
    }

    @Override
    public void deleteByCarId(String deleteByCarId) {
        accessoryDao.deleteByCarId(deleteByCarId);
    }
}
